<?php 
 include_once dirname(__FILE__)."/config.php";
 class dev_users_principal{
		 protected $_result;
		 protected $_cnn;
		 protected $_id_user;
		 protected $_type_user;
		 protected $_id_inscription;
		 protected $_username;
		 protected $_passwd;
		 protected $_is_connected;
		 public function get_name_table(){ return "dev_users";}
		 public function get_name_id_user(){ return "id_user";}
		 public function get_name_type_user(){ return "type_user";}
		 public function get_name_id_inscription(){ return "id_inscription";}
		 public function get_name_username(){ return "username";}
		 public function get_name_passwd(){ return "passwd";}
		 public function get_name_is_connected(){ return "is_connected";}
		 public function set_id_user($parametre){  $this->_id_user=$parametre;}	
		 public function set_type_user($parametre){  $this->_type_user=$parametre;}	
		 public function set_id_inscription($parametre){  $this->_id_inscription=$parametre;}	
		 public function set_username($parametre){  $this->_username=$parametre;}	
		 public function set_passwd($parametre){  $this->_passwd=$parametre;}	
		 public function set_is_connected($parametre){  $this->_is_connected=$parametre;}	
		 public function get_result(){ return $this->_result;}
		 public function get_id_user(){ return $this->_id_user;}
		 public function get_type_user(){ return $this->_type_user;}
		 public function get_id_inscription(){ return $this->_id_inscription;}
		 public function get_username(){ return $this->_username;}
		 public function get_passwd(){ return $this->_passwd;}
		 public function get_is_connected(){ return $this->_is_connected;}
public function __construct(){

		 	$this->_cnn=new databaseconnect();

		 }

 public function INSERT()
{

$sql=" INSERT INTO 
 dev_users(
			type_user,
			id_inscription,
			username,
			passwd,
			is_connected)
 VALUES(
			'".$this->_type_user."',
			'".$this->_id_inscription."',
			'".$this->_username."',
			'".$this->_passwd."',
			'".$this->_is_connected."')";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function UPDATE()
{

 $sql="";
if(!empty($this->_type_user)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
type_user='".$this->_type_user."'";
}
if(!empty($this->_id_inscription)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
id_inscription='".$this->_id_inscription."'";
}
if(!empty($this->_username)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
username='".$this->_username."'";
}
if(!empty($this->_passwd)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
passwd='".$this->_passwd."'";
}
if(!empty($this->_is_connected)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
is_connected='".$this->_is_connected."'";
}
$sql="UPDATE 
dev_users SET 
 ".$sql."
								WHERE id_user ='".$this->_id_user."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function DELETE(){

 $sql="DELETE FROM 
dev_users 
 
									WHERE id_user ='".$this->_id_user."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function TRANCATE(){

 $sql="DELETE FROM 
dev_users ";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function SELECT($constraint="",$pagination="")
{

$sql=" SELECT 
 		id_user,
		type_user,
		id_inscription,
		username,
		passwd,
		is_connected
 FROM 
 dev_users";
if($constraint){$sql.=" WHERE 1=1 ".$constraint;}if($pagination){$sql.=$pagination;}
$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}
public function fetch_object(){
$row=mysql_fetch_object($this->_result);
 if($this->_result){
 if($row){
		$this->_id_user=$row->id_user;
		$this->_type_user=$row->type_user;
		$this->_id_inscription=$row->id_inscription;
		$this->_username=$row->username;
		$this->_passwd=$row->passwd;
		$this->_is_connected=$row->is_connected;
		return $row;
		}else{
					return false;
				}

			}else{
				//echo 'Erreur d\'execution de requette de selection';	
			}
			

		}

}
?>